<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/17 0017
  Time: 上午 10:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>天禾汽车租赁系统-权限管理-添加</title>

    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/common.css">

</head>
<body>
<div class="wrap-padding-15">
    <span class="layui-breadcrumb">
          <a href="/" target="_top">首页</a>
          <a href="/permission">权限管理</a>
          <a><cite>增加</cite></a>
     </span>

    <div class="box-form">
        <form action="/permission/save" method="post" class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">资源名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="permisname"  lay-verify="required" placeholder="请输入资源名称" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">资源类型：</label>
                <div class="layui-input-block">
                    <select name="permistype"  lay-verify="required" lay-filter="type">
                        <option value="0">请选择资源类型</option>
                        <option value="1">模块</option>
                        <option value="2">功能</option>
                        <option value="3">按钮</option>
                        <option value="4">附属操作</option>
                        <option value="9">默认资源</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item layui-hide" id="parentIdDiv">
                <label class="layui-form-label">上级目录：</label>
                <div class="layui-input-block">
                    <select name="parentid" id="parentId" lay-filter="parentId">
                    </select>
                </div>
            </div>

            <div class="layui-form-item layui-hide" id="uriDiv">
                <label class="layui-form-label">URL地址：</label>
                <div class="layui-input-block">
                    <input type="text" name="relateurl"  placeholder="请输入权限路径" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item layui-hide" id="idNameDiv">
                <label class="layui-form-label">按钮id：</label>
                <div class="layui-input-block">
                    <input type="text" name="btnid"  placeholder="请输入按钮id" autocomplete="off" class="layui-input">
                </div>
            </div>

            <%--<div class="layui-form-item">
                <label class="layui-form-label">资源编码：</label>
                <div class="layui-input-block">
                    <input type="text" name="permiscode"  lay-verify="required" placeholder="请输入权限排序" autocomplete="off" class="layui-input">
                </div>
            </div>--%>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formSubmit">提交</button>
                    <a href="/permission"><button type="button" class="layui-btn layui-btn-primary">取消</button></a>
                </div>
            </div>
        </form>
    </div>

</div>






<script src="/static/plugins/jquery.js"></script>
<script src="/static/plugins/layui/layui.js"></script>
<script>

    layui.use(['element','layer','form'], function(){
        var form = layui.form;
        var element = layui.element;
        //监听提交
       /* form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });*/

        var $parentIdDiv = $("#parentIdDiv");
        var $uriDiv = $("#uriDiv");
        var $idNameDiv = $("#idNameDiv");
        var $parentId = $("#parentId");

        form.on('select(type)',function(data){
            var val = data.value;

            if(val>1){
                $uriDiv.removeClass("layui-hide").find("input").attr("lay-verify","required");
                if(val != 9){
                    $parentIdDiv.removeClass("layui-hide").find("select").attr("lay-verify","required");
                }else{
                    $parentIdDiv.addClass("layui-hide").find("select").removeAttr("lay-verify")
                }
                if(val==3){
                    $idNameDiv.removeClass("layui-hide").find("input").attr("lay-verify","required");
                }else{
                    $idNameDiv.addClass("layui-hide").find("input").removeAttr("lay-verify")

                }

            }else{
                $uriDiv.addClass("layui-hide").find("input").removeAttr("lay-verify")
                $parentIdDiv.addClass("layui-hide").find("select").removeAttr("lay-verify")
            }

            if(val >= 2 && val<= 4){
                $.ajax({
                    url:"/permission/type",
                    type:"get",
                    data:{type:val == 2 ? 1 : 2},
                    dataType:"json",
                    success:function(respData){
                        if(respData.code==1){
                            $parentId.empty()
                            $.each(respData.data,function(i,rowData){
                                $parentId.append('<option value="'+rowData.permisid+'">'+rowData.permisname+'</option>')
                            })
                            form.render('select');
                        }else{

                        }

                    },
                    error:function () {
                    }
                })
            }
        })


    });


</script>
</body>
</html>
